package flexo.scene;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class Scene extends Node
{
	public static final String ID = "scene";
	
	protected List<Instance> instanceList;
	
	public Scene(String name)
	{
		super(name);
		instanceList = new LinkedList<Instance>();
	}
	
	boolean addEntity(Node node, Entity entity)
	{
		Instance i = new Instance(node,entity);
		
		boolean contains = false;
		for (Instance il : instanceList)
		{
			if (il.compareTo(i) == 0)
			{
				contains = true;
			}
		}
		
		if (!contains)
		{
			instanceList.add(i);
			return true;
		}
		return false;
	}
	
	void removeEntity(Node node, Entity entity)
	{
		Iterator<Instance> iter = instanceList.iterator();
		while (iter.hasNext())
		{ 
			Instance i = iter.next();
			if (i.node == node && i.entity == entity)
			{
				iter.remove();
			}
		}
	}
	
	public List<Instance> getInstanceList(flexo.scene.Entity.Type type)
	{
		Iterator<Instance> iter = instanceList.iterator();
		List<Instance> ret = new ArrayList<Instance>();
		
		while (iter.hasNext())
		{
			Instance i = iter.next();
			if (i.getEntity().getType() == type)
			{
				ret.add(i);
			}
		}
		return ret;
	}
}
